import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_web_count_down_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/ext.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/inspec_task_page/run_task_page/run_task_detail/run_task_detail_controller.dart';

/// 执行任务详情
class RunTaskDetailPage extends StatelessWidget {
  RunTaskDetailPage({super.key});

  final controller = Get.put(RunTaskDetailController());

  /// 是否完成
  /// [i] 正常：0；存在隐患：1；未排查：2；其他：3 待排查：4
  /// 需求改动,只显示已完成和未完成状态
  Widget _ok(int? i) {
    // const String text = '';
    // const Color color = Color(0xFFA5A9C8);
    switch (i) {
      // case 0:
      //   text = '已完成';
      //   color = const Color(0xFF33A9FF);
      //   break;
      // return SvgPicture.asset(AppImages.icon_ok);
      // case 1:
      //   text = '存在隐患';
      //   color = const Color(0xffFD6B6B);
      //   break;
      // return SvgPicture.asset(AppImages.icon_un_normal);
      // case 2:
      //   text = '未排查';
      //   color = const Color(0xffFFCE24);
      //   break;
      // return SvgPicture.asset(AppImages.icon_no_ok);
      // case 3:
      //   text = '其他';
      //   color = const Color(0xFF5C6DFF);
      //   break;
      case 4:
        // text = '未完成';
        // color = const Color(0xFFA5A9C8);
        // break;
      return SvgPicture.asset(AppImages.icon_no_ok);
      default:
        // text = '已完成';
        // color = const Color(0xFF33A9FF);
        // break;
      return SvgPicture.asset(AppImages.icon_ok);
    }
    // return Container(
    //   alignment: Alignment.center,
    //   width: 55.w,
    //   height: 20.w,
    //   // color: color,
    //   decoration: BoxDecoration(
    //     color: color,
    //     borderRadius: BorderRadius.circular(4.r),
    //   ),
    //   transform: Matrix4.skew(-pi / 20, 0),
    //   child: Text(
    //     text,
    //     style: TextStyle(
    //       fontSize: 12.sp,
    //       height: 1.2,
    //       fontWeight: FontWeight.w400,
    //       color: const Color(0xFFffffff),
    //     ),
    //   ),
    // );
    // return Stack(
    //   alignment: Alignment.center,
    //   children: [
    //     SvgPicture.asset(
    //       AppImages.icon_un_normal,
    //       width: 40.w,
    //       height: 18.w,
    //       colorFilter: const ColorFilter.mode(color, BlendMode.srcIn),
    //     ),
    //     Text(
    //       text,
    //       style: TextStyle(
    //         fontStyle: FontStyle.italic,
    //         fontSize: 11.sp,
    //         fontWeight: FontWeight.w500,
    //         color: const Color(0xFFffffff),
    //       ),
    //     )
    //   ],
    // );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.bg_color_grey,
      appBar: CustomAppBar(
        titleText: controller.pageType == 0 ? '智能巡检' : '排查任务',
      ),
      body: GetBuilder(
        init: controller,
        builder: (_) {
          return Container(
            padding: EdgeInsets.symmetric(horizontal: 14.w),
            child: Column(
              children: [
                AppGaps.vGap16,
                Container(
                  width: double.infinity,
                  height: 40.w,
                  decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8)),
                  child: Row(
                    children: [
                      AppGaps.hGap6,
                      const Icon(Icons.location_on, color: AppColors.font_color_blue, size: 20),
                      Text(
                        '正在进行定位追踪，请打开手机定位功能！',
                        style: TextStyle(
                          fontSize: 12.sp,
                        ),
                      ),
                    ],
                  ),
                ),
                AppGaps.vGap14,
                Expanded(
                  child: Container(
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(12),
                    ),
                    child: Column(
                      children: [
                        AppGaps.vGap12,
                        controller.taskCountDown != 0
                            ? CustomWebGasCountDownPage(
                                milliseconds: controller.taskCountDown,
                                title: '任务',
                                divisionColors: Colors.black,
                                fontColor: TextStyle(
                                  fontSize: 14.sp,
                                  color: Colors.black,
                                ),
                              )
                            : Container(),
                        AppGaps.vGap12,
                        Container(
                          height: 1,
                          color: const Color(0x33587DF5),
                        ),
                        AppGaps.vGap12,
                        Expanded(
                          child: ListView.builder(
                            itemCount: controller.taskList.length,
                            itemBuilder: (cxt, index) {
                              return Container(
                                padding: EdgeInsets.only(
                                  top: 12.w,
                                  bottom: 12.w,
                                  left: 10.w,
                                  right: 10.w,
                                ),
                                margin: EdgeInsets.only(
                                  bottom: 16.w,
                                  right: 12.w,
                                  left: 12.w,
                                ),
                                decoration: BoxDecoration(
                                    border: Border.all(width: 1, color: const Color(0x33587DF5)),
                                    borderRadius: BorderRadius.circular(12),
                                    color: const Color(0xFFF5F6FF)),
                                child: Column(
                                  children: [
                                    Row(
                                      children: [
                                        _ok(controller.taskList[index].checkStatus),
                                        AppGaps.hGap10,
                                        Expanded(
                                          child: Text(
                                            '${controller.taskList[index].troubleshootContent}',
                                            style: TextStyle(
                                              fontSize: 14.sp,
                                              fontWeight: FontWeight.w500,
                                            ),
                                          ),
                                        ),
                                        Visibility(
                                          visible: controller.getIsCanExecuted(controller.taskList[index]),
                                          child: SvgPicture.asset(
                                            AppImages.icon_run_task,
                                            width: 43.w,
                                            height: 20.w,
                                            // colorFilter: const ColorFilter.mode(Colors.white, BlendMode.srcIn),
                                          ),
                                        )
                                      ],
                                    ),
                                    AppGaps.vGap12,
                                    Align(
                                      alignment: Alignment.centerLeft,
                                      child: Text(
                                        '开始时间: ${controller.taskList[index].workStartTime ?? '-'}',
                                        style: TextStyle(
                                          fontSize: 12.sp,
                                          color: AppColors.font_color_gray,
                                        ),
                                      ),
                                    ),
                                    Align(
                                      alignment: Alignment.centerLeft,
                                      child: Text(
                                        '结束时间: ${controller.taskList[index].faultLastTime ?? '-'}',
                                        style: TextStyle(
                                          fontSize: 12.sp,
                                          color: AppColors.font_color_gray,
                                        ),
                                      ),
                                    ),
                                    Align(
                                      alignment: Alignment.centerLeft,
                                      child: Text(
                                        '完成时间: ${controller.taskList[index].checkTime ?? '-'}',
                                        style: TextStyle(
                                          fontSize: 12.sp,
                                          color: AppColors.font_color_gray,
                                        ),
                                      ),
                                    )
                                  ],
                                ),
                              ).click(() {
                                controller.goUndoneTask(index);
                              });
                            },
                          ),
                        )
                      ],
                    ),
                  ),
                )
              ],
            ),
          );
        },
      ),
    );
  }
}
